﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Traceability.APP.Application.Command.Traceability;
using Traceability.APP.DTOS;
using Traceability.Domain;
using Traceability.ErrorCode;

namespace Traceability.APP.Controllers
{
    /// <summary>
    /// API 控制器-溯源基本信息
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TraceabilityController : ControllerBase
    {
        private readonly IMediator mediator;

        public TraceabilityController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 溯源基本信息新增
        /// </summary>
        /// <param name="common"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> GetAdd(GetAddTraceabilityCommon common)
        { 
            return mediator.Send(common);
        }

        /// <summary>
        /// 溯源基本信息显示
        /// </summary>
        /// <param name="common"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<APIPing<TraceabilityDto>>> GetShow(string? Shop_Name,string? Batch,string? ShelfLife,string? Production,string? Enterprise,string? CreateName,string? UpdateName, int Pageidenx,int Pagesizer)
        {
            GetShowTraceabilityCommand command = new GetShowTraceabilityCommand();
            command.Shop_Name = Shop_Name;
            command.Batch = Batch;
            command.ShelfLife = ShelfLife;
            command.Production = Production;
            command.Enterprise = Enterprise;
            command.CreateName = CreateName;
            command.UpdateName = UpdateName;
            command.Pageidenx = Pageidenx;
            command.Pagesizer = Pagesizer;
            return mediator.Send(command);
        }

        /// <summary>
        /// 溯源基本信息删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> DelTrac(DelTraceabilityCommand command)
        {
            return mediator.Send(command);
        }

        /// <summary>
        /// 溯源基本信息修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> UpdateTrac(UpdateTraceabilityCommand command)
        { 
            return mediator.Send(command);
        }

        /// <summary>
        /// 溯源详情基本信息
        /// </summary>
        /// <param name="common"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<Traceability_Management>> GetOne([FromQuery] GetOneTraceabilityCommon common)
        {
            return mediator.Send(common);
        }

    }
}
